#include	<stdio.h>
#include    <stdlib.h>
#include	<fcntl.h>

main()
{
	int	fd ;
	int	newfd;
	char	line[100];

	fgets( line, 100, stdin ); printf("%s", line );//输入数据
	fgets( line, 100, stdin ); printf("%s", line );
	fgets( line, 100, stdin ); printf("%s", line );

	fd = open("data", O_RDONLY);//打开文件data

	newfd = dup2(fd,0);//复制data文件中数据到0
	
	
	if ( newfd != 0 )//数据复制失败
        {
		fprintf(stderr,"Could not duplicate fd to 0\n");
		exit(1);
	}
	close(fd);//关闭文件			

	fgets( line, 100, stdin ); printf("%s", line );//打印复制结果
	fgets( line, 100, stdin ); printf("%s", line );
	fgets( line, 100, stdin ); printf("%s", line );
}
